//
//  WBVisitorViewController.m
//  WeiBoOC
//
//  Created by 韩菲菲 on 16/8/9.
//  Copyright © 2016年 韩菲菲. All rights reserved.
//

#import "WBVisitorViewController.h"
#import "WBOAuthViewController.h"
#import "WBUserAccountViewModel.h"


@interface  WBVisitorViewController()



@end

@implementation WBVisitorViewController


//tableView的懒加载
- (UITableView *)tableView
{
    if(!_tableView)
    {
    
        _tableView = [[UITableView alloc] init];
    }
    
    return _tableView;
}

//判断是否登录
- (BOOL)isLogin
{
    return [WBUserAccountViewModel sharedWBUserAccountViewModel].isLogin;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}

-(void)loadView
{
    if(!self.isLogin)
    {//没登录的时候
        
        //创建导航栏的两个按钮
        [self setupNavBtn];
        //创建view
        self.visitorView = [[WBVisitorView alloc] init];
        
        
        __weak typeof(self) weakSelf = self;
        self.visitorView.modalBlock = ^(){
        
            [weakSelf btnClick];
        
        };
        
        self.view = self.visitorView;
    }else
    {
        //登录的时候，视图是tableView
        self.view = self.tableView;
        
        
    
    }

}



//添加导航栏上面的两个按钮
#pragma mark - 设置导航栏
- (void)setupNavBtn
{
    //设置左边注册按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(btnClick)];
    
    //设置右边登录按钮
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(btnClick)];

}

//按钮点击事件
- (void)btnClick
{
    
    //创建控制器
    WBOAuthViewController *vc = [[WBOAuthViewController alloc] init];
    //modal一个控制器
    
    [self presentViewController:[[UINavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];


}





@end
